
package br.eti.busarello;

import java.awt.BorderLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class FrameTest extends JFrame{
  private static final long serialVersionUID = 1L;
	
	private ComboLookAndFeels comboLookAndFeels = new ComboLookAndFeels();
	
	public FrameTest() {
		//setDefaultCloseOperation(EXIT_ON_CLOSE);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
		setSize(400,300);
		
		setLayout(new BorderLayout());
		
		JButton button = new JButton();
		
		add(button);
		
		add(comboLookAndFeels, BorderLayout.SOUTH);
		
		comboLookAndFeels.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println(comboLookAndFeels.getSelected());
				comboLookAndFeels.apllyLookAndFeel(FrameTest.this);
			}
		});
		
  }
	
	@Override
	public void dispose() {
		if(canClose()){
			super.dispose();
		}
	}
	
	private boolean canClose(){
		Window[] ownedWindows = getOwnedWindows();
		
		for (Window window : ownedWindows) {	    
			if(window.isVisible()){
	    	return false;
	    }
    }
		
		return true;
	}
	
	
	public static void main(String[] args) throws InterruptedException {
	  
		Thread.sleep(5000);
		new FrameTest().setVisible(true);
		
		
  }
}
